package cn.puge.mertisfront.service.impl;

import cn.puge.mertisfront.entity.PugeUserLogin;
import cn.puge.mertisfront.mapper.PugeUserLoginMapper;
import cn.puge.mertisfront.service.PugeUserLoginService;
import cn.puge.servicebase.exceptionhandler.PuGeiException;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LIJW
 * @since 2020-08-31
 */
@Service
public class PugeUserLoginServiceImpl extends ServiceImpl<PugeUserLoginMapper, PugeUserLogin> implements PugeUserLoginService {

    @Override
    public String getLoginToken(PugeUserLogin pugeUserLogin1) {


        QueryWrapper<PugeUserLogin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",pugeUserLogin1.getUsername());
        PugeUserLogin pugeUserLogin = baseMapper.selectOne(queryWrapper);

        if (pugeUserLogin==null){

            throw new PuGeiException(20001,"用户不存在");
        }



        if (StringUtils.isEmpty(pugeUserLogin1.getUsername()) && StringUtils.isEmpty(pugeUserLogin1.getPassword())){

            throw new PuGeiException(20001,"用户名或密码为空");
        }



        if (!pugeUserLogin.getUsername().equals(pugeUserLogin1.getUsername()) || !pugeUserLogin.getPassword().equals(pugeUserLogin1.getPassword())){
            throw new PuGeiException(20001,"用户名或密码错误");
        }
        return pugeUserLogin.getId();
    }
}
